package dto

import (
	"service/app/mode"
	"time"
)

/** 返回前端用户格式*/
type IresUserInfo struct {
	UserInfo UpdataUserDto    `json:"user_info" form:"user"`
	Roles    *[]mode.Db_roles `json:"roles" form:"roles"`
	/** 前端routes格式列表 perm字段为routes name*/
	Menus *[]mode.Db_menu `json:"menus" form:"menus"`
}

type LoginDto struct {
	Password string `form:"password" binding:"required" required_msg:"password为必填项目"`
	User     string `form:"user" binding:"required" required_msg:"user用户名为必填项目"`
}

type ReqPaginatUser struct {
	Page     int    `form:"page" json:"page" binding:"required" required_msg:"page 为必填项目"`
	Limit    int    `form:"limit" json:"limit" binding:"required" required_msg:"limite 为必填项目"`
	Keyword  string `form:"keyword" json:"keyword" binding:"omitempty" required_msg:"keyword 为必填项目,搜索的关键词"`
	Key      string `form:"key" json:"key" binding:"omitempty,oneof=id user created_at updated_at password gender nickname mobile avatar birthday last_login_time register_ip last_login_ip user_level_id" oneof_msg:"key 为选填项目,key搜索的属性名必须为id user created_at updated_at password gender nickname mobile avatar birthday last_login_time register_ip last_login_ip user_level_id"`
	Order    string `form:"order" json:"order" binding:"omitempty,oneof=asc desc" oneof_msg:"order 为必填项目 asc | desc"`
	OrderKey string `form:"orderkey" json:"orderkey" binding:"omitempty,oneof=id user created_at updated_at password gender nickname mobile avatar birthday last_login_time register_ip last_login_ip user_level_id" oneof_msg:"orderkey 为选填项目,key搜索的属性名必须为id user created_at updated_at password gender nickname mobile avatar birthday last_login_time register_ip last_login_ip user_level_id"`
}

//	type LoginDto struct {
//		User     string `formdata:"user",json:"user",binding:"required"`
//		Password string `formdata:"password",json:"password",binding:"required"`
//	}
type AdduserDto struct {
	Id              uint      `json:"id" form:"id"`
	User            string    `json:"user" form:"user" binding:"required" required_msg:"用户名为必填项目"`
	Password        string    `json:"password,omitempty" form:"password" binding:"required" required_msg:"password为必填项目"`
	Gender          int       `json:"gender" form:"gender" binding:"required" required_msg:"Gender 为必填项目"`
	Nickname        string    `json:"nickname" form:"nickname" binding:"required" required_msg:"Nickname 为必填项目"`
	Mobile          string    `json:"mobile" form:"mobile" binding:"required" required_msg:"Mobile 为必填项目"`
	Avatar          string    `json:"avatar" form:"avatar" binding:"required" required_msg:"Avatar 为必填项目"`
	Birthday        time.Time `json:"birthday" form:"birthday" binding:"required" required_msg:"Birthday 为必填项目"`
	Last_Login_Time time.Time `json:"last_login_time" form:"last_login_time"`
	Register_Ip     string    `json:"register_ip"`
	Last_Login_Ip   string    `json:"last_login_ip"`
	User_Level_Id   int       `json:"user_level_id"`
}

// type AdduserDto struct {
// 	Id              uint      `json:"id" form:"id"`
// 	User            string    `json:"user" form:"user" binding:"required" required_msg:"用户名为必填项目"`
// 	Password        string    `json:"password,omitempty" form:"password" binding:"required" required_msg:"password为必填项目"`
// 	Gender          int       `json:"gender" form:"gender" binding:"required" required_msg:"Gender 为必填项目"`
// 	Last_Login_Ip   string    `json:"last_login_ip" form:"last_login_ip" binding:"required" required_msg:"Last_Login_Ip 为必填项目"`
// 	User_Level_Id   int       `json:"user_level_id" form:"user_level_id" binding:"required" required_msg:"User_Level_Id 为必填项目"`
// 	Nickname        string    `json:"nickname" form:"nickname" binding:"required" required_msg:"Nickname 为必填项目"`
// 	Mobile          string    `json:"mobile" form:"mobile" binding:"required" required_msg:"Mobile 为必填项目"`
// 	Avatar          string    `json:"avatar" form:"avatar" binding:"required" required_msg:"Avatar 为必填项目"`
// 	Birthday        time.Time `json:"birthday" form:"birthday" binding:"required" required_msg:"Birthday 为必填项目"`
// 	Last_Login_Time time.Time `json:"last_login_time" form:"last_login_time" binding:"required" required_msg:"Last_Login_Time 为必填项目"`
// 	Register_Ip     string    `json:"register_ip" form:"register_ip" binding:"required" required_msg:"Register_Ip 为必填项目"`
// }

type UpdataUserDto struct {
	Id              uint      `uri:"id" json:"id" binding:"required" required_msg:"id为必填项目"`
	User            string    `json:"user" form:"user" binding:"required" required_msg:"用户名为必填项目"`
	Gender          int       `json:"gender" form:"gender" binding:"required" required_msg:"Gender 为必填项目"`
	Nickname        string    `json:"nickname" form:"nickname" binding:"required" required_msg:"Nickname 为必填项目"`
	Mobile          string    `json:"mobile" form:"mobile" binding:"required" required_msg:"Mobile 为必填项目"`
	Avatar          string    `json:"avatar" form:"avatar" binding:"required" required_msg:"Avatar 为必填项目"`
	Birthday        time.Time `json:"birthday" form:"birthday" binding:"required" required_msg:"Birthday 为必填项目"`
	Last_Login_Time time.Time `json:"last_login_time" form:"last_login_time" binding:"required" required_msg:"Last_Login_Time 为必填项目"`
	Last_Login_Ip   string    `json:"last_login_ip" form:"last_login_ip" binding:"required" required_msg:"Last_Login_Ip 为必填项目"`
}

func (m *AdduserDto) ConverToUserDao(userProfile *mode.Lz_user) {
	userProfile.User = m.User
	userProfile.Password = m.Password
	userProfile.Gender = m.Gender
	userProfile.Nickname = m.Nickname
	userProfile.Mobile = m.Mobile
	userProfile.Avatar = m.Avatar
	userProfile.Birthday = time.Now()
	m.Last_Login_Time = time.Now()
	// userProfile.Last_Login_Ip = m.Last_Login_Ip
	// userProfile.Last_Login_Time = m.Last_Login_Time
	userProfile.Register_Ip = m.Register_Ip
}

func (m *IresUserInfo) ConverToRes(userUpdata *mode.Lz_user) {
	m.UserInfo.Id = userUpdata.ID
	m.UserInfo.User = userUpdata.User
	m.UserInfo.Gender = userUpdata.Gender
	m.UserInfo.Nickname = userUpdata.Nickname
	m.UserInfo.Mobile = userUpdata.Mobile
	m.UserInfo.Avatar = userUpdata.Avatar
	m.UserInfo.Birthday = userUpdata.Birthday
	m.UserInfo.Last_Login_Ip = userUpdata.Last_Login_Ip
	m.UserInfo.Last_Login_Time = userUpdata.Last_Login_Time
}

// func (m *UpdataUserDto) ConverToRes(userUpdata *mode.Lz_user) *UpdataUserDto {
// 	var newUser UpdataUserDto
// 	newUser.Id = userUpdata.ID
// 	newUser.User = userUpdata.User
// 	newUser.Gender = userUpdata.Gender
// 	newUser.Nickname = userUpdata.Nickname
// 	newUser.Mobile = userUpdata.Mobile
// 	newUser.Avatar = userUpdata.Avatar
// 	newUser.Birthday = userUpdata.Birthday
// 	newUser.Last_Login_Ip = userUpdata.Last_Login_Ip
// 	newUser.Last_Login_Time = userUpdata.Last_Login_Time
// 	return &newUser
// }

// 不修改密码
func (m *UpdataUserDto) ConverToUpdata(userUpdata *mode.Lz_user) {
	userUpdata.ID = m.Id
	userUpdata.User = m.User
	userUpdata.Gender = m.Gender
	userUpdata.Nickname = m.Nickname
	userUpdata.Mobile = m.Mobile
	userUpdata.Avatar = m.Avatar
	userUpdata.Birthday = m.Birthday
	userUpdata.Last_Login_Ip = m.Last_Login_Ip
	userUpdata.Last_Login_Time = m.Last_Login_Time
}
